package yagl.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import yagl.agent.YJZYAgent;
import common.Const;
import common.MyUtils;
import common.BaseClasses.CommonAction;
import common.BaseClasses.util.IocUtil;

public class YJZYAction extends CommonAction{

	private YJZYAgent yjzyAgent;
	private  Map<Object, Object> resultMap;
	
	 public YJZYAction(){
	    	try {
				this.yjzyAgent=(YJZYAgent) IocUtil.getIocImpl("yagl/ioc/ioc-yjzy.xml","yjzyAgent");
			} catch (Throwable e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	    }
	 /**
	  * 查询并跳转至应急资源页
	  * @return
	  */
	 public String selectAllZy(){
		 Map map=new HashMap();
//		 paramMap.put("returnPageName", "toYjZyFenYePage");
		 resultMap=yjzyAgent.selectAllZy(1,getIntParameter("pageSize"),map);
		 setPageParam(resultMap);
		 return "toYjZyPage";
	 }
	 
	 /**
	  * 读取选择的资源数据并显示在编辑页面
	  */
	 public void findZyById(){
		 List list=yjzyAgent.findZyById(getParameter("zyId"));
		 writeStringToResponse(JSONArray.fromObject(list));
	 }
	 
	 /**
	  * 分页查询
	  * @return
	  */
	 public String findZyByPage(){
			paramMap.put("returnPageName", getParameter("returnPageName"));
			paramMap.put("teamName", getParameter("teamName",""));
		    paramMap.put("zyType", getParameter("zyType",""));
	    	Map map=new HashMap();
	    	map.put("teamName", getParameter("teamName",""));
	    	map.put("zyType", getParameter("zyType",""));
	    	resultMap=yjzyAgent.selectAllZy(pageBean.getCurrentPage(), pageBean.getPageSize(), map);
	        setPageParam(resultMap);
	    	return "toYjZyFenYePage";
	 }
	 
	 /**
	  * 根据筛选条件查询
	  * @return
	  */
	 public String searchZy(){
		 	Map map=new HashMap();
	    	map.put("teamName", getParameter("name"));
	    	map.put("zyType", getParameter("zyType"));
	    	System.out.println("++++++++++++++++"+map);
	    	//将查询条件存入到分页标签里面
	    	paramMap.put("returnPageName", "toYjZyFenYePage");
	    	paramMap.put("teamName", getParameter("name"));
	    	paramMap.put("zyType", getParameter("zyType"));
	    	System.out.println("-------------paramMap"+paramMap);

	    	resultMap=yjzyAgent.selectAllZy(1, getIntParameter("pageSize"), map);
	    	System.out.println("-------------"+resultMap);
	        setPageParam(resultMap);
	    	return "toYjZyFenYePage";
		 
	 }
	 /**
	  * 添加或更新
	  * @return
	  */
	 public String AddZy(){
		 String zyid=getParameter("zyId");
	    	Map map=new HashMap();
	    	if(zyid!=null&&!(zyid.equals(""))){
	    		map.put("id", zyid);
	    		map.put("office_phone", getParameter("office_phone"));
	    		map.put("phone", getParameter("phone"));
	    		map.put("tool", getParameter("tool"));
	    		map.put("goods_nm", getParameter("goods_nm"));
	    		map.put("eve_type", getParameter("eve_type"));
	    		map.put("remark", getParameter("remark"));
	    		map.put("team_nm", getParameter("team_nm"));
	    		map.put("goods_num", getParameter("goods_num"));
	    		map.put("resou_type", getParameter("zy_type"));
	    		map.put("yj_type", getParameter("yj_type"));
	    		map.put("link_man", getParameter("link_man"));
	    		yjzyAgent.updataZy(map);
	    		return null;
	    	}
	    	else{
	    		map.put("id", MyUtils.getUUID());
	    		map.put("office_phone", getParameter("office_phone"));
	    		map.put("phone", getParameter("phone"));
	    		map.put("tool", getParameter("tool"));
	    		map.put("goods_nm", getParameter("goods_nm"));
	    		map.put("eve_type", getParameter("eve_type"));
	    		map.put("remark", getParameter("remark"));
	    		map.put("team_nm", getParameter("team_nm"));
	    		map.put("goods_num", getParameter("goods_num"));
	    		map.put("resou_type", getParameter("zy_type"));
	    		map.put("yj_type", getParameter("yj_type"));
	    		map.put("link_man", getParameter("link_man"));
	    		System.out.println("---------map:"+map);
	    		yjzyAgent.insert(map);
	    		return "success";
	    	}
	 }
	 /**
	  * 删除
	  * @return
	  */
	 public void DeleteZy(){
		 	String zyIdArr=getParameter("zyIDdArr");
	    	String result=yjzyAgent.deleteZy(zyIdArr);
	    	writeStringToResponse(result);
	 }
	public YJZYAgent getYjzyAgent() {
		return yjzyAgent;
	}

	public void setYjzyAgent(YJZYAgent yjzyAgent) {
		this.yjzyAgent = yjzyAgent;
	}

	public Map<Object, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(Map<Object, Object> resultMap) {
		this.resultMap = resultMap;
	}
	 
}
